"use strict";
/* Controllers */
app.controller("taskBaselineAddController", ['$scope', '$location', '$rootScope', '$q', '$routeParams', 'taskBaselineAddService', function ($scope, $location, $rootScope, $q, $routeParams, taskBaselineAddService) {
    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id;

    $('.date').datetimepicker({
        locale: 'zh-cn',
        format: 'HH:mm:ss'
    });
    $('.date').on('dp.hide', function (e) {
        let currentInput = $(e.currentTarget).find('input')
        let eName = currentInput.attr('name')
        let p = $scope.vm.p
        p[eName] = currentInput.val()
        $scope.$apply()
    })

    var errorFn = function (result) {
        alert(result);
    };

    $scope.getTaskBaseline = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (res) {
            if (res.success && res.data) {
                vm.p = res.data
            } else {
                alert(res.msg);
            }
        };
        return taskBaselineAddService.getTaskBaseline(params, procFn, errorFn);
    };
    $scope.setTaskBaseline = function () {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (response) {
            if (response.success && response.data) {
                alert("保存成功！")
            } else {
                alert(response.msg);
            }
        };
        return taskBaselineAddService.setTaskBaseline(params, procFn, errorFn);
    };

    if (typeof (vm.p.id) != "undefined" && vm.p.id != 0) {
        $scope.getTaskBaseline()
    }
}]);


/* Services */
app.service('taskBaselineAddService', ['ajaxService', function (ajaxService) {

    this.setTaskBaseline = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/task_baseline/setTaskBaseline.do", successFunction, errorFunction);
    };

    this.getTaskBaseline = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/task_baseline/getTaskBaseline.do", successFunction, errorFunction);
    };

}]);

